package com.sx.micowell.framework.model

import com.example.mvvm.base.data.MutableLiveListData
import com.example.mvvm.base.data.SingleLiveEvent
import com.example.mvvm.base.vm.BaseViewModel
import com.example.mvvm.until.LogUtils
import com.example.mvvm.until.SPUtils
import com.example.mvvm.until.ToastUtils
import com.miloyu.modelnet.network.ApiResponse
import com.miloyu.modelnet.network.HttpClient
import com.miloyu.modelnet.network.tools.RxUtils
import com.miloyu.modelnet.response.LearnedCourseVO
import com.miloyu.modelnet.response.LearnedCourseWrap
import com.sx.micowell.framework.app.SPKey
import java.util.HashMap

/**
 * @Author: YY
 * @Time: 2021/8/17
 * @Describe TODO
 */
class CollectModel : BaseViewModel() {

    var collectListData: MutableLiveListData<LearnedCourseVO> = MutableLiveListData<LearnedCourseVO>()

    var deleteEvent: SingleLiveEvent<Void> = SingleLiveEvent();

    fun getCollectList() {

        addSubscribe(
            HttpClient.instance.apiService
                .getCollectList()
                .compose(RxUtils.compose())
                .subscribeWith(object : ApiResponse<LearnedCourseWrap>() {

                    override fun success(data: LearnedCourseWrap?, msg: String?) {
                        collectListData.value = data?.info
                    }

                    override fun onFail(e: Throwable?, errorMsg: String?) {
                        ToastUtils.showShort("$errorMsg")
                    }

                })
        )

    }

    fun deleteCollectCourse(id: String) {

        addSubscribe(
            HttpClient.instance.apiService
                .deleteCollectCourse(id)
                .compose(RxUtils.compose())
                .subscribeWith(object : ApiResponse<Void>() {

                    override fun success(data: Void?, msg: String?) {
                        ToastUtils.showShort("$msg")
                        deleteEvent.call()
                    }

                    override fun onFail(e: Throwable?, errorMsg: String?) {
                        ToastUtils.showShort("$errorMsg")
                    }

                })
        )

    }
}